//
//  RigisterVC.swift
//  DollarBuy
//
//  Created by 郑东喜 on 2016/11/7.
//  Copyright © 2016年 郑东喜. All rights reserved.
//  注册界面

import UIKit

class RigisterVC: MeBaseViewController {
    
    
  
    //用户名
    @IBOutlet weak var tfNum: UITextField!
    
    //密码
    @IBOutlet weak var tfPass: UITextField!
    
    //验证码
    @IBOutlet weak var tfAuto: UITextField!

    //确认密码
    @IBOutlet weak var tfConfirmPass: UITextField!
    
    //同意协议文本
    @IBOutlet weak var agreeLabel: UILabel!
    
    //同意图片显示是否
    @IBOutlet weak var isAgrreIimgShow: UIImageView!
    
    @IBOutlet weak var nickName: UITextField!
    //同意协议
    @IBAction func confirmAgree(_ sender: UIButton) {

        sender.isSelected = !localSave.bool(forKey: agreeLaw)

        if sender.isSelected {
            self.isAgrreIimgShow.isHidden = true
            localSave.set(sender.isSelected, forKey: agreeLaw)
        } else {
            self.isAgrreIimgShow.isHidden = false
            localSave.set(sender.isSelected, forKey: agreeLaw)
        }
        localSave.synchronize()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        //同意图片的显示状态根据单机同意按钮显示
        isAgrreIimgShow.isHidden = localSave.bool(forKey: agreeLaw)
        
        print(localSave.bool(forKey: agreeLaw))
    }
    
    //发送验证码
    @IBAction func sendAuto(_ sender: UIButton) {
        print("\((#file as NSString).lastPathComponent):(\(#line)):(\("发送验证码")))")
        
        self.sendRigisterMsg(tfNum: self.tfNum)
    }
    

    //注册
    @IBAction func rigisterSEL(_ sender: UIButton) {
        /**
         ## 注册
         封装了注册逻辑
         
         - tfNum            电话号码
         - tfAuto           验证码
         - tfPass           密码
         - tfconfirmPass    确认密码
         */
//        self.rigister(tfNum: self.tfNum, tfAuto: self.tfAuto, tfPass: self.tfPass, tfconfirmPass: self.tfConfirmPass)
        self.rigister(tfNum: self.tfNum, tfAuto: self.tfAuto, tfPass: self.tfPass, tfconfirmPass: self.tfConfirmPass, tfNickName: self.nickName)

    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //添加label手势事件
        self.agreeLabel.attributedText = CoTool.shareInstance.labelWithUnderLine(text: "同意注册协议")
        self.agreeLabel.isUserInteractionEnabled = true
        
        let tapGes = UITapGestureRecognizer.init(target: self, action: #selector(RigisterVC.clickLabel))
        self.agreeLabel.addGestureRecognizer(tapGes)

        // Do any additional setup after loading the view.

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}

// MARK:- 同意协议
extension RigisterVC {
    func clickLabel() {
        print("点击label")
    }
}

//记录同意图片的显示状态
extension RigisterVC {
    
}
